<template>
    <div class="todo-footer">
        <label>
            <input type="checkbox" v-model="isAllSelectComputed"/>
        </label>
        <span>
          <span>已完成{{todoComplete}}</span> / 全部{{todoLists.length}}
        </span>
        <button class="btn btn-danger" @click="mytipDeletAllComplete" v-show="todoComplete">清除已完成任务</button>
    </div>
</template>

<script>
    export default {
        name: "TodoFooter",
        props:{
            todoLists:Array,
            selectAll:Function,
            deletAllComplete:Function
        },
        data () {
            return {
                isSelectAll:false
            }
        },
        computed:{
            todoComplete () {
                // return this.todoLists.filter( item => item.complete).length;
                // 累加器
                return this.todoLists.reduce((proTotal,item) => {
                    return proTotal+(item.complete?1:0);
                },0);
            },
            isAllSelectComputed:{
                get () {
                    return this.todoComplete==this.todoLists.length && this.todoLists.length;
                },
                set (value) {
                    this.selectAll(value);
                }
            }
        },
        methods:{
            mytipDeletAllComplete () {
                if(window.confirm('确定删除所有已选项目吗？')){
                    this.deletAllComplete();
                }
            }
        }
    }
</script>

<style lang="stylus" scoped>
    /*footer*/
    .todo-footer {
        height: 40px;
        line-height: 40px;
        padding-left: 6px;
        margin-top: 5px;
    }

    .todo-footer label {
        display: inline-block;
        margin-right: 20px;
        cursor: pointer;
    }

    .todo-footer label input {
        position: relative;
        top: -1px;
        vertical-align: middle;
        margin-right: 5px;
    }

    .todo-footer button {
        float: right;
        margin-top: 5px;
    }

</style>